Modul 8 von 15 · 📖 4 min Lesezeit · ⏱ 30 min gesamt
FI-AE 09 Versionsverwaltung mit Git (EN)
Inhaltsverzeichnis (6 Abschnitte)
FI-AE 09 Version Control with Git
In this module, you will learn advanced Git techniques for professional software development. You will understand branching models such as Git Flow and Trunk-Based Development, master working with Pull Requests, can efficiently resolve merge conflicts, and know when to prefer Rebase over Merge.
Concepts and Background
- Branching Models
- Strategies for organizing development branches in Git that ensure teamwork and code quality. Git Flow establishes main, feature, release, and hotfix branches, while Trunk-Based Development focuses on short lifecycles and frequent merges to the main branch.
- Pull Requests
- A mechanism for code review and integration where changes in a branch are proposed and discussed before being merged into the target branch.
- Merge Conflicts
- Situations where Git cannot automatically decide how to merge changes because identical lines have been modified differently in both branches.
- Rebase vs. Merge
- Two strategies for integrating branches: Merge preserves the complete history, while Rebase rewrites the commits of a branch to the latest state of the target branch and creates a linear history.
Architecture Diagram
flowchart LR A[main/master] --> B[develop] B --> C[feature/xyz] B --> D[release/1.0] D --> E[hotfix/critical] C -->|Pull Request| B D -->|Pull Request| A E -->|Merge| A E -->|Merge| B
Practical Steps
- Create a new feature branch from the develop branch:
git checkout developgit checkout -b feature/new-feature - Implement your changes and commit regularly with meaningful messages:
git commit -m "Login form validated" - Push your branch to the remote repository:
git push origin feature/new-feature - Create a Pull Request via the Git web interface or with the CLI:
gh pr create --title "New Login Form" --body "Implements OAuth2 integration" - Resolve any merge conflicts locally:
Edit the conflict files and run:git pull origin developgit add .git commit -m "Conflict resolved" - After review, perform the merge:
git checkout developgit merge --no-ff feature/new-feature - Delete the feature branch after successful merge:
git branch -d feature/new-featuregit push origin --delete feature/new-feature - For releases, create a release branch from develop:
git checkout -b release/1.2.0 develop
Common Pitfalls
Further Resources
- Official Git Book (German translation)
- Git Flow - Vincent Driessen's Branching Model
- Trunk-Based Development - Official Resource
- Atlassian Git Tutorials (German)
- Git 2.30.0+ - New Features and Best Practices
Knowledge Check
Four questions for self-assessment. Click on each question to see the correct answer and explanation.
1. Which branching model prefers short lifecycles for feature branches and frequent merges to the main branch?
- A) Git Flow
- B) Trunk-Based Development
- C) Feature Branching
- D) Release Branching
Correct Answer: B. Trunk-Based Development focuses on short lifecycles and frequent merges, while Git Flow envisions longer lifecycles with specialized branch types.
2. What is the main advantage of Rebase over Merge when integrating branches?
- A) Rebase preserves the complete history of all commits
- B) Rebase creates a linear history without merge commits
- C) Rebase automatically resolves all merge conflicts
- D) Rebase only works with local repositories
Correct Answer: B. Rebase rewrites commits and creates a linear history, while Merge preserves commits from both branches and creates merge commits.
3> In which branching model is a hotfix branch typically derived from the main branch (main/master)?
- A) Trunk-Based Development
- B) Git Flow
- C) Forking Workflow
- D) Branch-per-Feature
Correct Answer: B. Git Flow specifies that hotfixes are derived directly from the main branch, while other models do not prescribe this.
4. What is the primary purpose of Pull Requests in Git?
- A) Automated testing of code changes
- B) Mechanism for code review and integration
- C) Resolving merge conflicts
- D) Creating new branches
Correct Answer: B. Pull Requests primarily serve for code review and controlled integration of changes, while other functions require separate tools or Git commands.